package cn.zyjblogs.nio;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class NIOFileChannel04 {
    public static void main(String[] args) {

        //创建文件的输入流
        try(FileInputStream fileInputStream = new FileInputStream("logo.png");
            FileOutputStream fileOutputStream = new FileOutputStream("logo2.png")) {
            FileChannel sourceChannel = fileInputStream.getChannel();

            FileChannel destchannel = fileOutputStream.getChannel();
            //使用transferFrom完成拷贝
            destchannel.transferFrom(sourceChannel,0,sourceChannel.size());
            sourceChannel.close();
            destchannel.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
